//
//  HomeSearchView.swift
//  HoneyBee
//
//  Created by point on 2018/5/10.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

class HomeSearchView: UIView {
    
    lazy var mapBtn:UIButton = UIButton(type: .custom)
    lazy var mytextField:UITextField = UITextField()
    fileprivate lazy var lineView:UIView = UIView()
    fileprivate lazy var myButtomView:UIView =  UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        //self.cornerForView(conrners: .allCorners, radius: 4)
    }
    
}

// MARK:- 加载UI
extension HomeSearchView {
    fileprivate func setupUI(){
        self.addSubview(mytextField)
        self.addSubview(mapBtn)
        self.addSubview(lineView)
        self.addSubview(myButtomView)
        
        mytextField.snp.makeConstraints { (make) in
            mytextField.snp.makeConstraints { (make) in
                make.left.equalTo(self).offset(7)
                make.top.equalTo(self).offset(5)
                make.right.equalTo((self)).inset(43)
                make.height.equalTo(30)
            }
        }
        mytextField.backgroundColor = UIColor.init(hex:"f4f4f5")
        mytextField.layer.cornerRadius = 15
        mytextField.clipsToBounds = true
        mytextField.placeholder = "点击此处搜索机构"
        mytextField.font = UIFont.systemFont(ofSize: 14)
        let leftView =  UIImageView()
        leftView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
        
        
        let imgView = UIImageView()
        leftView.addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 20, height: 20))
            make.center.equalToSuperview()
        }
        imgView.image = UIImage(named: "pen")
        
        mytextField.leftViewMode = .always
        mytextField.leftView = leftView
        
        lineView.snp.makeConstraints { (make) in
            make.height.equalTo(5)
            make.top.equalTo(mytextField.snp.bottom).offset(5)
            make.right.left.equalTo(self).inset(0)
        }
        lineView.backgroundColor = UIColor.init(hex:"f4f4f5")
        myButtomView.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.left.right.bottom.equalTo(self)
        }
        
        
        let vView = UIView()
        myButtomView.addSubview(vView)
        vView.snp.makeConstraints { (make) in
            make.width.equalTo(2)
            make.height.equalTo(15)
            make.left.equalTo(self).offset(10)
            make.centerY.equalTo(myButtomView)
        }
        vView.backgroundColor = UIColor.init(hex:"17bbfe")
        let label = UILabel.init(UIColor.black, 15, "为您推荐")
        myButtomView.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.centerY.equalTo(vView)
            make.left.equalTo(vView.snp.right).offset(10)
        }
        
        mapBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 43, height: 50))
            make.right.equalTo(self)
            make.centerY.equalTo(mytextField)
        }
        
        //mapBtn.adjustsImageWhenDisabled = true //.withRenderingMode(.alwaysOriginal)
        mapBtn.setImage(UIImage(named: "dingwei"), for: .normal)
        mapBtn.setImage(UIImage(named: "dingwei"), for: .highlighted)
    }
}
